package edu.nf.db.util.result;

import edu.nf.db.util.ResultSetHandler;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author lzp
 * @Date 2024-05-10
 * 抽象的集合结果集处理器
 */
public abstract class AbstractListHandler<T> implements ResultSetHandler<List<T>> {

    @Override
    public List<T> handle(ResultSet rs) throws SQLException {
        List<T> list = new ArrayList<>();
        while (rs.next()){
            list.add(handlerRow(rs));
        }
        return list;
    }

    /**
     * 处理行处理方法，交由子类做不同的实现
     * @param rs
     * @return
     */
    public abstract T handlerRow(ResultSet rs) throws SQLException;
}
